package homework;

import java.util.Scanner;

/**
 * @classname:demo09
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/8 17:38
 * @version: 0.1
 * @since:1.8
 */
public class demo09 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        while (sb.length() < 6) {
            System.out.println("请输入2个英文字母");
            String s = input.nextLine();
            if (s.matches("^([a-zA-Z]{2})$")) {
                sb.append(s);
            } else {
                System.out.println("录入不合法，请重新录入");
            }
        }
        //转换大小写
        String lowerCase = sb.toString().toLowerCase();

        int formIndex = 0;
        int count = 0;
        while (true) {
            int index = lowerCase.indexOf("a", formIndex);
            //如果返回为-1说明没有找到制定的字符
            if (index == -1) {
                break;
            }
            formIndex = index + 1;
            count++;
        }
        System.out.println("共出现a/A:" + count + "次");
    }
}
